fix(cli): resume older working-directory sessions in /sessions and --continue - #2952
fix(cli): resume older working-directory sessions in /sessions and --continue#2952creatiVision wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 49ca402 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5abe8379c8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // A workspace-scoped read that returns nothing can still hide sessions | ||
| // that exist on disk but were not projected into the read model (e.g. | ||
| // legacy/v1-era sessions recorded with only `workDir`, or sessions in | ||
| // alias buckets). Coalesce onto the authoritative source so `/sessions` | ||
| // (working-directory scope) and `--continue` never hide them. Unscooped |
There was a problem hiding this comment.
Move method-body narration into the file header
This newly added explanatory block sits inside listRecent and narrates the implementation, while the scoped v2 guide requires comments to live solely in the top-of-file /** */ block and describe external responsibilities. Remove the inline narration or fold the relevant responsibility-level context into the existing module header.
AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L36-L38
Useful? React with 👍 / 👎.
7362425 to
90ff48b
Compare
dbcc055 to
9e8b269
Compare
ff0d093 to
fc28606
Compare
ecf7d01 to
bb75ffd
Compare
|
Rebased onto latest
The PR is now clean, mergeable, and ready for review. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bdeb5cf089
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const page = await index.listRecent({}); | ||
| const previous = page.items.find((summary) => summary.cwd === workDir); | ||
| const previous = page.items.find( | ||
| (summary) => summary.cwd !== undefined && resolve(summary.cwd) === resolve(workDir), |
There was a problem hiding this comment.
Compare Windows paths case-insensitively
When the same Windows working directory is entered with different component casing (for example, a stored C:/Users/Alice/Repo versus a current C:/users/alice/repo), resolve() makes the paths absolute and normalizes their syntax but preserves that casing, so this equality still fails and --continue silently starts a new session. Use the repository's Windows-aware workspace-root normalization, or otherwise case-fold Windows-shaped paths, before comparing them.
Useful? React with 👍 / 👎.
| const previous = page.items.find( | ||
| (summary) => summary.cwd !== undefined && resolve(summary.cwd) === resolve(workDir), | ||
| ); |
There was a problem hiding this comment.
Validate cached cwd before resolving it
When a persisted read-model row has all required summary fields but a malformed optional cwd such as null or a number, isSessionSummaryShape accepts it, this check treats it as defined, and resolve(summary.cwd) can throw instead of skipping the unusable session. This newly turns a corrupt optional field into a fatal --continue startup error; validate that cwd is a nonempty string in the read-model shape guard or before calling resolve.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49ca402013
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const page = await index.listRecent({}); | ||
| const previous = page.items.find((summary) => summary.cwd === workDir); | ||
| const previous = page.items.find( | ||
| (summary) => summary.cwd !== undefined && resolve(summary.cwd) === resolve(workDir), |
There was a problem hiding this comment.
Resolve symlink aliases before comparing work directories
When a session was created through the SDK/API with a symlinked workDir (for example, /work/repo-link) and kimi --continue is later launched from the symlink target (/srv/repo), this still starts a fresh session. resolve() only performs lexical path normalization and leaves the symlink component intact, so the two paths remain unequal; use filesystem canonicalization such as realpath before comparing, with an appropriate fallback for unavailable paths.
Useful? React with 👍 / 👎.
Problem
Since the v2 engine became the CLI default (#2627),
/sessions(working-directory scope) andkimi --continuestop surfacing the older sessions of the current working directory — most notably legacy/v1-era sessions recorded with onlyworkDir(nocwd)./sessionsshows an empty cwd list and--continuesilently starts a fresh session.Related: #2951 (report), #1650 (open, describes the same bucket-coordination gap).
What changed
Two spots covered:
v2 session index read-model miss on a workspace-scoped
listRecent(packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.ts): when the minidb read model answers an empty page for aworkspaceIds-scoped query, coalesce onto the authoritative directory read so sessions that exist on disk but were not projected (legacyworkDir-only, alias buckets) are never hidden. This fixes the TUI/sessionsworking-directory scope.--continuematching (apps/kimi-code/src/cli/v2/run-v2-print.ts): normalize thecwd === workDircomparison withresolve(...)(matching the existing--sessionguard) so path variations (symlink, trailing slash, case) no longer drop the last session.Changed
packages/agent-core-v2/src/app/sessionIndex/sessionIndexService.tsapps/kimi-code/src/cli/v2/run-v2-print.tspackages/agent-core-v2/test/app/sessionIndex/sessionIndex.test.ts@moonshot-ai/kimi-codepatchOut of scope
Checklist